//
//  ProblemDetailViewController.m
//  shopping
//
//  Created by 徐双 on 2017/9/1.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "ProblemDetailViewController.h"
#import "ProblemDetailViewCell.h"

@interface ProblemDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView * tableView;
@property (nonatomic, strong) NSMutableDictionary *dictData;
@property (nonatomic, strong) UILabel *label1;

@end

@implementation ProblemDetailViewController

- (void)viewWillAppear:(BOOL)animated{
    
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"解决方案"];
    [self creationDate];
    
    [self setUpTitle];
    [self setUpContent];
    
}

-(void)setUpTitle{
    
    //设置分割线
    UIView *viewOfLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, 2)];
    [self.view addSubview:viewOfLine];
    viewOfLine.backgroundColor = getColor(@"CCCCCC");
    
    UIView * grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 2, DEF_SCREEN_WIDTH, 45)];
    [self.view addSubview:grayView];
    grayView.backgroundColor = getColor(@"F5F5F5");
    
    //设置label
    self.label1 = [[UILabel alloc] init];

    self.label1.textColor = getColor(@"222222");
    
    self.label1.font = [UIFont systemFontOfSize:14];
    
    [grayView addSubview:self.label1];
    
    [self.label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(grayView).with.offset(16);
        make.left.equalTo(grayView).with.offset(13);
        make.height.offset(13);
        make.width.offset(100);
    }];
    
    //设置分割线
    UIView *viewOfLine2 = [[UIView alloc] initWithFrame:CGRectMake(0,2 + 45, DEF_SCREEN_WIDTH, 2)];
    [self.view addSubview:viewOfLine2];
    viewOfLine2.backgroundColor = getColor(@"CCCCCC");
}
-(void)setUpContent{
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 45 +2 +2, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64 -49);
    
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 800;
     self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去掉分割线
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:self.tableView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ProblemDetailViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
}

- (void)creationDate{
    
    _dictData = [[NSMutableDictionary alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    //    //    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    //    NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    //
    //    [productParams setValue:token forKey:@"token"];
    NSString *str = [NSString stringWithFormat:@"%ld", (long)self.articleId];
    
    [productParams setValue:str forKey:@"articleId"];
    [[MNetworkHandler sharedInstance]conURL:adminUserGetHelpDetails networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"status"]intValue]==1) {
            
            _dictData = [returnData objectForKey:@"data"];
            NSLog(@"!!!!!!!!!!!!!!!%@", _dictData);
            self.label1.text = [_dictData objectForKey:@"articleTitle"];
            
            [self.tableView reloadData];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    ProblemDetailViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.ContentLabel.text = [_dictData objectForKey:@"articleContent"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewAutomaticDimension;
}


@end
